/**
Company: Sarkar software technologys
WebSite: http://www.sarkar.cn
Author: yeganaaa
Date : 8/5/18
Time: 4:24 PM
 */

package com.ug_project.dict.engine.indextable

class DataBlockIterator(val thisBlock: DataBlock) : Iterator<DataBlock> {
    var currentBlock = thisBlock
    var canNext = true
    override fun hasNext(): Boolean = (currentBlock.nextBlockId > 0 || currentBlock.dataIndex > 0) && canNext

    override fun next(): DataBlock {
        return if (currentBlock.dataIndex > 0) currentBlock.also {
            canNext = false
        } else DataBlock(thisBlock.indexTable, currentBlock.nextBlockId).also {
            currentBlock = it
        }
    }
}